class MyLocalStorage {
  setItem(key, val) {
    localStorage.setItem(key, val)
  }

  setJsonItem(key, val) {
    return this.setItem(key, JSON.stringify(val))
  }

  getItem(key) {
    return localStorage.getItem(key)
  }

  getJsonItem(key) {
    let val = this.getItem(key)
    if (val) {
      try {
        val = JSON.parse(val)
      } catch (e) {
        // nothing
      }
    }
    return val
  }

  removeItem(key) {
    localStorage.removeItem(key)
  }

  clear() {
    localStorage.clear()
  }
}

const myLocalStorage = new MyLocalStorage()
export default myLocalStorage
